import {API,header} from 'config/config.js'
import {openTime} from 'request/time.js'//获取营业时间
import {time_range,isWant} from './tool.js'
import {creatOrde} from 'request/orde.js'//创建订单


//支付接口
async function payment(orde){
	if(!isWant(orde))return
	var time=await openTime()
	var key= time_range(time[1].data.data.start_time,time[1].data.data.end_time)
	if(key){
		creatOrde(orde).then(res=>{
			if(res[1].data.code==200){
				var pay=res[1].data.data
				console.log(res[1].data.data)
				uni.requestPayment({
					...pay,
					success(){
						uni.showToast({
						    title: '支付成功',
							image:"../../static/ico/correct.png",
						    duration: 1500
						});
					},
					fail(){
						uni.showToast({
						    title: '支付失败',
							image:"../../static/ico/error.png",
						    duration: 1500
						});
					}
				})
			}else{
				uni.showToast({
				    title: '创建订单失败',
					image:"../../static/ico/warn2.png",
				    duration: 1500
				});
			}
		})
	}else{
		uni.showToast({
		    title: '下单时间',
			image:"../../static/ico/warn2.png",
		    duration: 1500
		});
		setTimeout(()=>{
			uni.showToast({
			    title: '11:30-17:30',
				image:"../../static/ico/warn2.png",
			    duration: 1500
			});
		},1500)
	}
}


export{
	payment
}